package com.itheima.udp2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Server {


    public static void main(String[] args) throws Exception {
        //1.创建接受对象
        DatagramSocket ds = new DatagramSocket(8888);

        while (true) {
            //2.创建接受容器
            DatagramPacket dp = new DatagramPacket(new byte[1024], 1024);
            //3.接受
            ds.receive(dp);
            //4.查看数据
            byte[] data = dp.getData();
            int length = dp.getLength();
            String s = new String(data, 0, length);
            System.out.println(s);

        }
        //5.释放资源
        //ds.close();


    }
}
